<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../include/taglib.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="../../include/inhead.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="renderer" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<meta name="keywords" content="E爱车 洗车 到店洗车" />
<meta name="description" content="E爱车" />
<link rel="shortcut icon" href="${ctx}/static/imges/favicon.ico" />
<title>绑定手机</title>
<link rel="stylesheet" type="text/css" href="${ctx}/static/css/autoinn/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/static/css/autoinn/font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/static/css/autoinn/washCar.css" />
<style type="text/css">
			body{
				background-color: #f0efed;
			}
			
			.container{
				padding-left: 0px;
				padding-right: 0px;
			}
			
			.row{
				margin-left: 0px;
				margin-right: 0px;
			}
			
			.list-group-item:first-child{
				border-top-left-radius: 0px;
				border-top-right-radius: 0px;
			}
			
			.list-group-item:last-child{
				border-bottom-right-radius: 0px;
				border-bottom-left-radius: 0px;
			}
			
			.active a{
				color: #EF8A55;
			}
			
			a:hover{
				color: #919191;
				text-decoration: none;
			}
		</style>
	<script type="text/javascript" src="${ctx}/static/js/autoinn/jquery/jquery-1.7.min.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/autoinn/bootstrap/bootstrap.min.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/autoinn/jquery/jquery.raty.js"></script>
	</head>
<body>
		<div class="container">
			<div class="orange-orange-a row pf text-center f14 border-1 bdc-e6e6e6 bgc-f8f8f8 pt-5 pb-5 z99 w h45 line-height-35 pr" style="left: 0; top: 0;">
				<div class="col-xs-4 line-height-35 text-left pl-15 pr-0 pt-0">
				</div>
				<div class="col-xs-4 pr-0 pl-0 text-center">绑定手机号</div>
			</div>
			<div class="pb-50 pt-50 row pl-15 pr-15">
				 <form id="myform" name="myform"  method="post" action="#" >
					<input type="hidden" id="wxaccount" name="wxaccount" value="${wxaccount}"/>
					
					<input type="hidden" id="openid" name="openid" value="${openid }" />

				    <div class="col-xs-12 pl-0 pr-0 pt-10">
				    	<div class="co1 pt-20 pl-5 pb-10 text-center">为方便商家与您联系,请验证手机号</div>
					     <div class="form-group">
						  <label class="control-label sr-only" for="phone">手机号</label>
						  <div class="input-group">
						    <span class="input-group-addon"><i class="fa fa-phone"></i></span>
						    <input type="tel" class="form-control h35" id="phone"  name ="phone" placeholder="填写手机号">
						  </div>
						 </div>
				         <div class="input-group">
				         	<div id='waitminute' style="display: none;">60</div>
							<span class="input-group-addon"><i class="fa fa-lock"></i></span>
							<input type="text" class="form-control h35" id="verfiycode" name="verfiycode" placeholder="填写验证码">
					        <span class="input-group-btn">  
			                   <button id="yzm" class="btn btn-default" type="button"  onclick="isExist()" >获取验证码</button>  
			                </span>  

				         </div>
				    </div>
			        <div class="col-xs-12 pl-0 pr-0 pt-10 pb-20">
			            <button class="btn btn-orange btn-block " type="button" onclick="postRegUser()">绑定手机</button>
			        </div>
			    </form>
			</div>
		</div>
		<script type="text/javascript" src="${ctx}/static/js/autoinn/jquery/jquery.placeholder.js"></script>
		<script type="text/javascript" src="${ctx}/static/js/autoinn/common.js"></script>
		<script type="text/javascript" src="${ctx}/static/js/autoinn/washCar.js"></script>
		<script type="text/javascript">
            var PARENT_URL='',
                ERROR_MSG = '',
                SUCCESS_MSG = '',
                INFO_MSG = '',
                WARNING_MSG = '';
        </script>
		<script type="text/javascript">
		//隐藏微信分享按钮
		document.addEventListener("WeixinJSBridgeReady",
				function onBridgeReady(){
					WeixinJSBridge.call("hideOptionMenu")
				}
		);
		$(document).ready(function(){
		   
		});
		
		

		//检测手机号码是否存在
		function isExist()
		{
			var	phone = $('#phone').val();
			var Mobile=/^(13[0-9]|15[012356789]|17[0-9]|18[012356789]|14[57])[0-9]{8}$/;
		    if(phone=='' ||phone.length!=11)
			{
		    	 $.Global.Notice.WarningTopNotice('请输入正确的手机号码');
			  $('#phone').focus();
			  return;
			}
		    if(!Mobile.test(phone)){
		    	 $.Global.Notice.WarningTopNotice('请输入正确的手机号码');
		  	  $('#phone').focus();
		  	  return;
		    }
		    var wxaccount=$('#wxaccount').val();
			var openid=$('#openid').val();
			$.ajax({
					type : "POST",
					url :'${ctx}/weixin/f/autoinn/user/findByPhone',
					data : {
						phone : phone,
						wxaccount : wxaccount,
						openid : openid
					},
					dataType: "json",    
					success : function(json)
					{
						
						if(json.code==0)
					   {
					     getVerfiyCode();
					   }else if(json.code==-1)
					   {
						   $.Global.Notice.WarningTopNotice("请输入正确的手机号码"); 
					   }else if(json.code==1)
					   {
						   $.Global.Notice.WarningTopNotice("请不要重复绑定"); 
					   }else if(json.code==2){
						   $.Global.Notice.WarningTopNotice("此手机号已经被其他帐号绑定"); 
					   }else{
						   $.Global.Notice.WarningTopNotice("非微信请求"); 
					   } 
					},
					error:function()
					{ 
						$.Global.Notice.ErrorTopNotice("服务器错误"); 
					}
			});
		}

		
		
		
	var timeID;
	//获取验证码
	function getVerfiyCode()
	{
	         
	    phone = $('#phone').val();
	    var Mobile=/^(13[0-9]|15[012356789]|18[01236789]|14[57])[0-9]{8}$/;
	    if(phone=='' ||phone.length!=11)
		{
	    	$.Global.Notice.WarningTopNotice('请输入正确的手机号码');
		  $('#phone').focus();
		  return;
		}
	    if(!Mobile.test(phone)){
	    	$.Global.Notice.WarningTopNotice('请输入正确的手机号码');
	  	  $('#phone').focus();
	  	  return;
	    }
	    $('#yzm').removeAttr('onclick');
	    var time=parseInt($('#waitminute').text());
	    timeID = window.setInterval(daojishi,1000);
	    $.ajax({
	            type : "POST",
	            url :'${ctx}/weixin/f/autoinn/user/getVerfiyCode',
	            data :'phone='+phone,
	            dataType: "json",  
	            success : function(json)
	            { 
	                if(json.code==0)
	                {
	                	$.Global.Notice.InfoTopNotice('验证码已发送');
	                }else if(json.code==1){
	                  var seconds=json.seconds;
	                  $('#waitminute').text(seconds);
	                  $.Global.Notice.InfoTopNotice('请等待'+seconds+'分钟');
	                  var time=parseInt($('#waitminute').text());
	                  timeID = window.setInterval(daojishi,1000);    
	                }else{
	                	$.Global.Notice.WarningTopNotice(json.msg);
	                }
	     
	            },
	            error:function()
	            {
	                    $('.growlUI').fadeOut(1800);  
	            }
	         });
	        //开始倒计时
	        function daojishi()
	        {
	          if (time == 0) {                
	              window.clearInterval(timeID);//停止计时器
	              $("#yzm").removeAttr("disabled");//启用按钮
	              $("#yzm").val("重新发送验证码");
	          }
	          else {
	              $("#yzm").text( time + "秒");
	              time--;
	          }
	        }

	}


	//注册post数据
	function postRegUser()
	{
	   phone = $('#phone').val();
	   code = $('#verfiycode').val();

	   $('#error_phone').hide();
	   $('#error_num').hide();
	  /*  $('#input_phone').removeClass('special text-active');
	   $('#input_num').removeClass('special text-active'); */


	   if(phone == '')
	   {
		   $.Global.Notice.WarningTopNotice('您还没有输入手机号码：）');
		  $('#phone').focus();
		  return;
	   }
	   
	   if( phone.length!=11)
		{
		   // 错误信息
		   $.Global.Notice.WarningTopNotice('请输入正确的手机号码');
		  $('#phone').focus();
		  return;
		}
	   if(code == '')
	   {
		  $.Global.Notice.WarningTopNotice('您还没有输入验证码：）');
		  $('#verfiycode').focus();
		  return;
	   }
	   
	   reg = /^\w+$/;
	   if(code == '' ||code.length !=6 || !code.match( reg ) )
	   {
		   $.Global.Notice.WarningTopNotice('验证码不正确，请重新输入');
		  $('#verfiycode').focus();
		  return;
	   }
	   
	   var wxaccount=$('#wxaccount').val();
		var openid=$('#openid').val();
		$.ajax({
				type : "POST",
				url : '${ctx}/weixin/f/autoinn/user/bindPhoneNum',
				data : {
					phone : phone,
					wxaccount : wxaccount,
					openid : openid,
					verfiycode : code
				},
				dataType : "json",
				success : function(data) {
					if (data.code == 0) {
						//alert(data.url);
						$("#myform").attr("action","${ctx}"+data.url);
						$("#myform").submit();
					} else {
						$.Global.Notice.WarningTopNotice(data.msg);
					}

				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {

					$.Global.Notice.ErrorTopNotice("服务器错误");
				}
			});

		}

		</script>
		<script>
		var _hmt = _hmt || [];
		(function() {
		  var hm = document.createElement("script");
		  hm.src = "//hm.baidu.com/hm.js?3987c54e2c6d6c399fa4aca3fb9a7ef9";
		  var s = document.getElementsByTagName("script")[0]; 
		  s.parentNode.insertBefore(hm, s);
		})();
		</script>
	</body>
</html>